package com.lovi.homework;

public class Homework01_ {
    public static void main(String[] args) {
        String str = "abcdef";
        System.out.println(str);
        int startIndex = 1;
        int endIndex = 5;
        //进行字符串的反转，不会影响原字符串
        String str2 = reverseStr(str, startIndex, endIndex);
        System.out.println(str2);
    }

    private static String reverseStr(String str, int startIndex, int endIndex) {
        //先判断不合法的情况
        if(!(str!=null &&startIndex<endIndex && endIndex < str.length() && startIndex>=0)){
            throw new RuntimeException("参数不合法");
        }

        char[] array = str.toCharArray();
        char temp = ' ';
        for (int i = startIndex, j = endIndex; i < j; i++, j--) {
            temp = array[i];
            array[i] = array[j];
            array[j] = temp;
        }

        return new String(array);
    }
}

